package ml.ml.Dao;

import java.util.List;

import ml.ml.Clases.Publicacion;

import org.easycassandra.persistence.EasyCassandraManager;
import org.easycassandra.persistence.Persistence;

/**
 * TODO: description
 */
public class PublicacionDAO {

    private static final long serialVersionUID = 1L;
    private static PublicacionDAO INSTANCE = null;
    
    private PublicacionDAO(){
    	this.persistence = EasyCassandraManager.getPersistence("mlp", "186.18.34.21", 9160);
    }
    
    public static PublicacionDAO getInstance(){
    	if (INSTANCE == null){
    		INSTANCE = new PublicacionDAO();
    	}
    	return INSTANCE;
    }
    
    
    /* Acá termina el singleton */
    
    private static Publicacion publicacion = new Publicacion();

    private Persistence persistence;

    public void create(final Publicacion bean) {

        this.persistence.insert(bean);

    }

    public void remove(final Publicacion bean) {

        this.persistence.delete(bean);
    }

    public void remove(final Long id) {
        this.persistence.deleteByKeyValue(id, Publicacion.class);
    }

    public void update(final Publicacion bean) {
        this.persistence.update(bean);
    }

    public Publicacion retrieve(final Object id) {
        return (Publicacion) this.persistence.findByKey(id, publicacion.getClass());
    }

    @SuppressWarnings("unchecked")
    public List<Publicacion> listAll() {
        return this.persistence.findAll(publicacion.getClass());
    }

    @SuppressWarnings("unchecked")
    public List<Publicacion> listByIndex(final Object index) {
        return this.persistence.findByIndex(index, publicacion.getClass());
    }

    

}
